package controllers;

import play.*;
import play.mvc.*;

import views.html.*;

import play.data.*;
import static play.data.Form.*;
import models.*;

public class OptionArticleCont extends Controller {

	static Form<OptionArticle> optionArticleForm = form(OptionArticle.class);

	public static Result index() {
		return redirect(routes.OptionArticleCont.optionArticles());
	}

	public static Result optionArticles() {
		return ok(optionArticle.render(Utilisateur.find.where().eq("pseudo_utilisateur", session("pseudo_utilisateur")).findUnique(),OptionArticle.all(), optionArticleForm));
	}

	public static Result newOptionArticle() {
		Form<OptionArticle> filledForm = form(OptionArticle.class).bindFromRequest();
		if(filledForm.hasErrors())
		{
			//return badRequest(views.html.index.render(OptionArticle.all(), filledForm));
			return ok("Hello world");
		}
		else
		{
			OptionArticle.create(filledForm.get());
			return redirect(routes.OptionArticleCont.optionArticles());
		}
	}

	public static Result deleteOptionArticle(Integer id) {
		OptionArticle.delete(id);
		return redirect(routes.OptionArticleCont.optionArticles());

	}
}
